package com.minelx.util.date;

import java.util.stream.Stream;

public class Day {

	public static final long DAY_AS_MILLIS = 86400000L;

	private final Clock clock;

	Day(Clock clock) {
		this.clock = clock;
	}

	public String format(String pattern) {
		return clock.format(pattern);
	}

	public Stream<Day> days() {
		return clock.offsets(ClockUnit.DAY, 1)
				.map(Day::new);
	}

	public Stream<Day> daysBetween(Day destination) {
		return days().limit(dayCountsBetween(destination));
	}

	public Day offset(long dayCounts) {
		return new Day(clock.offset(ClockUnit.DAY, (int) dayCounts));
	}

	public long dayCountsBetween(Day destination) {
		return (destination.millis() - this.millis()) / DAY_AS_MILLIS;
	}

	public long millis() {
		return clock.self().getTimeInMillis();
	}

	public Month month() {
		return new Month(clock.convertPreciseToMonth());
	}

	public static Day of(int year, int month, int day) {
		return new Day(Clock.of(year, month, day));
	}

	public static Day from(String text) {
		return new Day(Clock.from(text));
	}
}